﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web;
using System.Transactions;
using AjaxControlToolkit;
using System.Globalization;
public partial class Main_Inventory_PurchaseOrder : System.Web.UI.Page
{
    //Global Datatable, varable and the List
    #region
    Datautility DU = new Datautility();
    DataTable DTBindPO = new DataTable();
    DataTable DTInternational = new DataTable();
    DataTable DTMain = new DataTable();
    DataTable DTBindInterPO = new DataTable();
    //pageID=417 for the Page ID.
    string strsql = "";
    string Body = "";
    int ControlCounter = 5;
    string POID = "";
    List<string> LstList;
    List<string> LstQty;
    List<string> LstItemName;
    List<string> LstAutoExtName;
    List<string> LstUnit;
    List<string> LstMPN;
    List<string> LstTaxRate;
    List<string> LstRateExcTax;
    List<string> LstAmountPayable;
    #endregion
    //Create Webservice To get the ItemName and Itemcode in the AutocompleteExtender
    #region
    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetItemName(string prefixText)
    {
        Datautility db = new Datautility();
        //Page page = HttpContext.Current.Handler as Page;
        //DropDownList ddlLeasedType = (DropDownList)page.FindControl("ddlleased"); 
        //System.Web.UI.Page Page = new System.Web.UI.Page();
        //DropDownList ddlLeasedType = (DropDownList)Page.FindControl("ddlleased");        
        DataTable dt = db.getdata("select TOP 8 ITMCODE,ITMDESC,IVR_ITEM.ITMID as ITMID from IVR_ITEM inner join IVR_ITEMOPENBAL on IVR_ITEM.ITMID=IVR_ITEMOPENBAL.ITMID where IVR_ITEM.ITMCODE like '%" + prefixText + "%' or IVR_ITEM.ITMDESC like '%" + prefixText + "%'");
        List<string> ItemDesc = new List<string>();
        List<int> ItemId = new List<int>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            ItemDesc.Add(Convert.ToString(dt.Rows[i]["ITMDESC"]) + "\\" + dt.Rows[i]["ITMCODE"].ToString());
        }
        return ItemDesc;
    }
    #endregion
    //Maintain the Viewstate of the AddNew
    #region
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        LstList = (List<string>)ViewState["LstList"];
        LstItemName = (List<string>)ViewState["LstItemName"];
        LstAutoExtName = (List<string>)ViewState["LstAutoExtName"];
        LstMPN = (List<string>)ViewState["LstMPN"];
        LstQty = (List<string>)ViewState["LstQty"];
        LstUnit = (List<string>)ViewState["LstUnit"];
        LstRateExcTax = (List<string>)ViewState["LstRateExcTax"];
        LstTaxRate = (List<string>)ViewState["LstTaxRate"];
        LstAmountPayable = (List<string>)ViewState["LstAmountPayable"];
        if (LstList != null)
        {
            int count = Convert.ToInt32(LstList.Count.ToString());
            for (int i = 0; i < count; i++)
            {
                ControlCounter++;
                Label lbl = new Label();
                lbl.ID = LstList[i].ToString();
                lbl.Text = ControlCounter.ToString();

                HtmlTableRow htrow = new HtmlTableRow();
                htrow.ID = "htrow" + ControlCounter.ToString();

                HtmlTableCell htcell1 = new HtmlTableCell();
                htcell1.ID = "htcell1" + ControlCounter.ToString();
                htcell1.VAlign = "Top";
                htcell1.Width = "35%";
                TextBox txtItem = new TextBox();
                txtItem.ID = LstItemName[i].ToString();
                txtItem.Width = Unit.Percentage(99);
                txtItem.AutoPostBack = true;
                txtItem.CssClass = "input";
                txtItem.Attributes.Add("onPaste", "return false;");
                txtItem.TextChanged += new EventHandler(txtItem_TextChanged);
                htcell1.Controls.Add(txtItem);

                HtmlTableCell htcell8 = new HtmlTableCell();
                htcell8.ID = "htcell8" + ControlCounter.ToString();
                AjaxControlToolkit.AutoCompleteExtender autoItem = new AjaxControlToolkit.AutoCompleteExtender();
                autoItem.ID = LstAutoExtName[i].ToString();
                autoItem.ServiceMethod = "GetItemName";
                autoItem.MinimumPrefixLength = 1;
                autoItem.CompletionInterval = 0;
                autoItem.OnClientItemSelected = "duplicaterow";
                autoItem.CompletionListCssClass = "AutoExtender";
                autoItem.CompletionListItemCssClass = "AutoExtenderList";
                autoItem.CompletionListHighlightedItemCssClass = "AutoExtenderHighlight";
                autoItem.EnableCaching = false;
                autoItem.TargetControlID = txtItem.ID;
                htcell8.Controls.Add(autoItem);


                HtmlTableCell htcell2 = new HtmlTableCell();
                htcell2.ID = "htcell2" + ControlCounter.ToString();
                htcell2.VAlign = "Top";
                htcell2.Width = "10%";
                TextBox txtQty = new TextBox();
                txtQty.ID = LstQty[i].ToString();
                txtQty.Width = Unit.Percentage(99);
                txtQty.MaxLength = 12;
                txtQty.Attributes.Add("onKeyPress", "return isNumber(event);");
                txtQty.Attributes.Add("onblur", "calcQty(); calcAmt();");
                txtQty.AutoCompleteType = AutoCompleteType.Disabled;
                txtQty.CssClass = "inputnumber";
                htcell2.Controls.Add(txtQty);


                HtmlTableCell htcell3 = new HtmlTableCell();
                htcell3.ID = "htcell3" + ControlCounter.ToString();
                htcell3.VAlign = "Top";
                htcell3.Width = "15%";
                TextBox txtUnit = new TextBox();
                txtUnit.ID = LstUnit[i].ToString();
                txtUnit.Width = Unit.Percentage(99);
                txtUnit.CssClass = "input";
                txtUnit.Style["background-color"] = "lightGray";
                txtUnit.Attributes.Add("onKeyPress", "return false");
                txtUnit.AutoCompleteType = AutoCompleteType.Disabled;
                htcell3.Controls.Add(txtUnit);

                HtmlTableCell htcell6 = new HtmlTableCell();
                TextBox txtRateExcTax = new TextBox();
                htcell6.ID = "htcell6" + ControlCounter.ToString();
                htcell6.VAlign = "Top";
                htcell6.Width = "15%";
                txtRateExcTax.ID = LstRateExcTax[i].ToString();
                txtRateExcTax.Width = Unit.Percentage(99);
                txtRateExcTax.CssClass = "inputnumber";
                txtRateExcTax.MaxLength = 10;
                txtRateExcTax.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
                txtRateExcTax.Attributes.Add("onblur", "calcAmt()");
                txtRateExcTax.AutoCompleteType = AutoCompleteType.Disabled;
                htcell6.Controls.Add(txtRateExcTax);

                HtmlTableCell htcell7 = new HtmlTableCell();
                htcell7.ID = "htcell7" + ControlCounter.ToString();
                htcell7.VAlign = "Top";
                htcell7.Width = "15%";
                TextBox txtAmountPayable = new TextBox();
                txtAmountPayable.ID = LstAmountPayable[i].ToString();
                txtAmountPayable.Width = Unit.Percentage(97);
                txtAmountPayable.CssClass = "inputnumber";
                txtAmountPayable.Style["background-color"] = "lightGray";
                txtAmountPayable.Attributes.Add("onKeyPress", "return false");
                txtAmountPayable.AutoCompleteType = AutoCompleteType.Disabled;
                htcell7.Controls.Add(txtAmountPayable);

                HtmlTableCell htcell9 = new HtmlTableCell();
                htcell9.ID = "htcell9" + ControlCounter.ToString();
                htcell9.Width = "10%";
                htcell9.VAlign = "Top";
                DropDownList ddlmpn = new DropDownList();
                ddlmpn.ID = LstMPN[i].ToString();
                ddlmpn.Width = Unit.Percentage(97);
                ddlmpn.CssClass = "input";
                htcell9.Controls.Add(ddlmpn);


                htrow.Cells.Add(htcell1);
                htrow.Cells.Add(htcell3);
                htrow.Cells.Add(htcell9);
                htrow.Cells.Add(htcell2);
                htrow.Cells.Add(htcell6);
                htrow.Cells.Add(htcell7);
                htrow.Cells.Add(htcell8);
                tblItem.Rows.Add(htrow);
            }
        }
    }
    protected void btnAddMore_Click(object sender, EventArgs e)
    {
        ControlCounter++;
        Label lbl = new Label();
        lbl.ID = "lbl" + ControlCounter.ToString();
        lbl.Text = ControlCounter.ToString();
        LstList.Add(lbl.Text);

        HtmlTableRow htrow = new HtmlTableRow();
        htrow.ID = "htrow" + ControlCounter.ToString();

        HtmlTableCell htcell1 = new HtmlTableCell();
        htcell1.ID = "htcell1" + ControlCounter.ToString();
        htcell1.VAlign = "Top";
        htcell1.Width = "35%";
        TextBox txtItem = new TextBox();
        txtItem.ID = "txtItem" + ControlCounter.ToString();
        txtItem.Width = Unit.Percentage(99);
        txtItem.AutoPostBack = true;
        txtItem.CssClass = "input";
        txtItem.Attributes.Add("onPaste", "return false;");
        txtItem.TextChanged += new EventHandler(txtItem_TextChanged);
        htcell1.Controls.Add(txtItem);
        LstItemName.Add(txtItem.ID);

        HtmlTableCell htcell8 = new HtmlTableCell();
        htcell8.ID = "htcell8" + ControlCounter.ToString();
        AutoCompleteExtender autoItem = new AutoCompleteExtender();
        autoItem.ID = "AutoItem" + ControlCounter.ToString();
        autoItem.ServiceMethod = "GetItemName";
        autoItem.MinimumPrefixLength = 1;
        autoItem.CompletionInterval = 0;
        autoItem.EnableCaching = false;
        autoItem.OnClientItemSelected = "duplicaterow";
        autoItem.CompletionListCssClass = "AutoExtender";
        autoItem.CompletionListItemCssClass = "AutoExtenderList";
        autoItem.CompletionListHighlightedItemCssClass = "AutoExtenderHighlight";
        autoItem.TargetControlID = txtItem.ID;
        htcell8.Controls.Add(autoItem);
        LstAutoExtName.Add(autoItem.ID);

        HtmlTableCell htcell2 = new HtmlTableCell();
        htcell2.ID = "htcell2" + ControlCounter.ToString();
        htcell2.VAlign = "Top";
        htcell2.Width = "10%";
        TextBox txtQty = new TextBox();
        txtQty.ID = "txtQty" + ControlCounter.ToString();
        txtQty.Width = Unit.Percentage(99);
        txtQty.CssClass = "inputnumber";
        txtQty.MaxLength = 12;
        txtQty.Attributes.Add("onKeyPress", "return isNumber(event);");
        txtQty.Attributes.Add("onblur", "calcQty(); calcAmt();");
        txtQty.AutoCompleteType = AutoCompleteType.Disabled;
        htcell2.Controls.Add(txtQty);
        LstQty.Add(txtQty.ID);

        HtmlTableCell htcell3 = new HtmlTableCell();
        htcell3.ID = "htcell3" + ControlCounter.ToString();
        htcell3.VAlign = "Top";
        htcell3.Width = "15%";
        TextBox txtUnit = new TextBox();
        txtUnit.ID = "txtUnit" + ControlCounter.ToString();
        txtUnit.Width = Unit.Percentage(99);
        txtUnit.CssClass = "input";
        txtUnit.Style["background-color"] = "lightGray";
        txtUnit.Attributes.Add("onKeyPress", "return false");
        txtUnit.AutoCompleteType = AutoCompleteType.Disabled;
        htcell3.Controls.Add(txtUnit);
        LstUnit.Add(txtUnit.ID);


        HtmlTableCell htcell6 = new HtmlTableCell();
        TextBox txtRateExcTax = new TextBox();
        htcell6.ID = "htcell6" + ControlCounter.ToString();
        htcell6.Width = "15%";
        htcell6.VAlign = "Top";
        txtRateExcTax.ID = "txtRateExcTax" + ControlCounter.ToString();
        txtRateExcTax.Width = Unit.Percentage(99);
        txtRateExcTax.CssClass = "inputnumber";
        txtRateExcTax.MaxLength = 10;
        txtRateExcTax.Attributes.Add("onKeyPress", "return isNumberKey(this.id,event)");
        txtRateExcTax.Attributes.Add("onblur", "calcAmt()");
        txtRateExcTax.AutoCompleteType = AutoCompleteType.Disabled;
        htcell6.Controls.Add(txtRateExcTax);
        LstRateExcTax.Add(txtRateExcTax.ID);


        HtmlTableCell htcell7 = new HtmlTableCell();
        htcell7.ID = "htcell7" + ControlCounter.ToString();
        htcell7.Width = "15%";
        htcell7.VAlign = "Top";
        TextBox txtAmountPayable = new TextBox();
        txtAmountPayable.ID = "txtAmountPayable" + ControlCounter.ToString();
        txtAmountPayable.Width = Unit.Percentage(97);
        txtAmountPayable.CssClass = "inputnumber";
        txtAmountPayable.Style["background-color"] = "lightGray";
        txtAmountPayable.Attributes.Add("onKeyPress", "return false");
        txtAmountPayable.AutoCompleteType = AutoCompleteType.Disabled;
        htcell7.Controls.Add(txtAmountPayable);
        LstAmountPayable.Add(txtAmountPayable.ID);


        HtmlTableCell htcell9 = new HtmlTableCell();
        htcell9.ID = "htcell9" + ControlCounter.ToString();
        htcell9.Width = "10%";
        htcell9.VAlign = "Top";
        DropDownList ddlmpn = new DropDownList();
        ddlmpn.ID = "ddlmpn" + ControlCounter.ToString();
        ddlmpn.Width = Unit.Percentage(97);
        ddlmpn.CssClass = "input";
        htcell9.Controls.Add(ddlmpn);
        LstMPN.Add(ddlmpn.ID);


        htrow.Cells.Add(htcell1);
        htrow.Cells.Add(htcell3);
        htrow.Cells.Add(htcell9);
        htrow.Cells.Add(htcell2);
        htrow.Cells.Add(htcell6);
        htrow.Cells.Add(htcell7);
        htrow.Cells.Add(htcell8);
        tblItem.Rows.Add(htrow);

        ViewState["LstList"] = LstList;
        ViewState["LstItemName"] = LstItemName;
        ViewState["LstAutoExtName"] = LstAutoExtName;
        ViewState["LstQty"] = LstQty;
        ViewState["LstMPN"] = LstMPN;
        ViewState["LstUnit"] = LstUnit;
        ViewState["LstRateExcTax"] = LstRateExcTax;
        ViewState["LstTaxRate"] = LstTaxRate;
        ViewState["LstAmountPayable"] = LstAmountPayable;
        hidControl.Value = ControlCounter.ToString();
    }
    protected void txtItem_TextChanged(object sender, EventArgs e)
    {
        TextBox txt = (TextBox)sender;
        string txtid = txt.ID.ToString().Substring(7);
        int rowIndex = Convert.ToInt32(txtid.ToString());
        TextBox txtUnit = (TextBox)tblItem.Rows[rowIndex].FindControl("txtUnit" + rowIndex.ToString());
        TextBox txtQty = (TextBox)tblItem.Rows[rowIndex].FindControl("txtQty" + rowIndex.ToString());
        TextBox txtRateExcTax = (TextBox)tblItem.Rows[rowIndex].FindControl("txtRateExcTax" + rowIndex.ToString());
        DropDownList ddlTaxType = (DropDownList)tblItem.Rows[rowIndex].FindControl("ddlTaxType" + rowIndex.ToString());
        TextBox txtRateIncTax = (TextBox)tblItem.Rows[rowIndex].FindControl("txtRateIncTax" + rowIndex.ToString());
        TextBox txtAmountPayable = (TextBox)tblItem.Rows[rowIndex].FindControl("txtAmountPayable" + rowIndex.ToString());
        HiddenField hidTaxRate = (HiddenField)tblItem.Rows[rowIndex].FindControl("hidTaxRate" + rowIndex.ToString());
        DropDownList DDLMPNNo = (DropDownList)tblItem.Rows[rowIndex].FindControl("ddlmpn" + rowIndex.ToString());

        if (txt.Text != "")
        {
            if (txt.Text.Contains("\\"))
            {
                string[] itemname = txt.Text.Split('\\');
                string sql = "select UOMSYMBOL from IVR_UOM inner join IVR_ITEM on IVR_UOM.UOMID=IVR_ITEM.PRIMARY_UOMID where IVR_ITEM.ITMCODE='" + itemname[1] + "'";
                DataTable DT = DU.getdata(sql);
                if (DT.Rows.Count > 0)
                {
                    txtUnit.Text = DT.Rows[0][0].ToString();
                    string SqlMPN = "Select ID,MPNCODE from IVR_ITEM_MPN inner join IVR_ITEM on IVR_ITEM.ITMID=IVR_ITEM_MPN.ITEMID where IVR_ITEM.ITMCODE='" + itemname[1] + "'";
                    DataTable Dtmpn = DU.getdata(SqlMPN);
                    if (Dtmpn.Rows.Count > 0)
                    {
                        DDLMPNNo.DataSource = Dtmpn;
                        DDLMPNNo.DataTextField = "MPNCODE";
                        DDLMPNNo.DataValueField = "ID";
                        DDLMPNNo.DataBind();
                        DDLMPNNo.Items.Insert(0, new ListItem(" ", "0"));
                    }
                    else
                    {
                        DDLMPNNo.Items.Clear();
                    }
                }
            }
            else
            {
                txt.Text = ""; txtUnit.Text = "";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "itemcheck", "ItemCheck();", true);
            }
        }
        else
        {
            ddlTaxType.SelectedValue = "0";
            txtRateExcTax.Text = "";
            hidTaxRate.Value = "";
            txtQty.Text = "";
            txtUnit.Text = "";
            txtRateIncTax.Text = "";
            txtAmountPayable.Text = "";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "calcQty(); calcAmt();", true);
        }
    }
    #endregion
    //Page Load event and the Function which is Required in the page load
    #region
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["userid"] == null)
        {
            if (Request.QueryString["redirect"] != null)
            {
                if (Request.QueryString["redirect"].ToString() == "po")
                {
                    Response.Redirect("~/SessionExpired.aspx?redirect=po");
                }
            }
            else
            {
                Response.Redirect("~/SessionExpired.aspx");
            }
        }
        else
        {
            //For Checking the Permission of the Page according to the User.
            string Pagepermission = "select PAGE_ID,PAGE_ADD,PAGE_VIEW,USERID,USERNAME as EmailID from USER_PERMISSION inner join LOGIN on USER_PERMISSION.USER_ID=LOGIN.USERID where USER_ID='" + Session["userid"].ToString() + "' and PAGE_ID=417";
            DataTable dt = DU.getdata(Pagepermission);
            if (dt.Rows.Count > 0)
            {
                if (Request.QueryString["action"] != null)
                {
                    if (dt.Rows[0]["PAGE_ADD"].ToString() == "True")
                    {
                        #region Postback
                        if (!IsPostBack)
                        {
                            divData.Visible = true;
                            LstList = new List<string>();
                            ViewState["LstList"] = LstList;

                            LstQty = new List<string>();
                            ViewState["LstQty"] = LstQty;

                            LstItemName = new List<string>();
                            ViewState["LstItemName"] = LstItemName;

                            LstAutoExtName = new List<string>();
                            ViewState["LstAutoExtName"] = LstAutoExtName;

                            LstUnit = new List<string>();
                            ViewState["LstUnit"] = LstUnit;

                            LstMPN = new List<string>();
                            ViewState["LstMPN"] = LstMPN;

                            LstRateExcTax = new List<string>();
                            ViewState["LstRateExcTax"] = LstRateExcTax;

                            LstTaxRate = new List<string>();
                            ViewState["LstTaxRate"] = LstTaxRate;

                            LstAmountPayable = new List<string>();
                            ViewState["LstAmountPayable"] = LstAmountPayable;

                            Bind_Format();
                            BindLocations();
                            Bind_CompanyAddress();
                        }
                        #endregion
                        hidemailId.Value = dt.Rows[0]["EmailID"].ToString();
                    }
                    else
                    {
                        Response.Redirect("~/AccessDenied.aspx");
                    }
                }
                if (Request.QueryString["View"] != null)
                {
                    if (dt.Rows[0]["PAGE_VIEW"].ToString() == "True")
                    {
                        if (Request.QueryString["View"].ToString() == "True")
                        {
                            BindCustomData();
                            BindInternationalPO();
                            divprint.Visible = true;
                            divData.Visible = false;
                        }                        
                    }
                    else
                    {
                        Response.Redirect("~/AccessDenied.aspx");
                    }
                }                
            }
            else
            {
                Response.Redirect("~/AccessDenied.aspx");
            }
        }
        if (Request.QueryString["v"] != null)
        {
            if (Request.QueryString["v"].ToString() == "u")
            {
                lblMsg.Attributes.Add("class", "true");
                lblMsg.Text = "Purchase Order Created Successfully";
            }
        }
        //BindDeliveryAddress(DdlLocation.SelectedValue);      
    }
    protected void Bind_Format()
    {
        strsql = "Select TFOID,FORMATNAME from IVR_TRANFORMAT where TRANTYPE='8'";
        //strsql = "Select TFOID,FORMATNAME from IVR_TRANFORMAT";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            ddlFormat.DataSource = DT;
            ddlFormat.DataTextField = "FORMATNAME";
            ddlFormat.DataValueField = "TFOID";
            ddlFormat.DataBind();
            ddlFormat.Items.Insert(0, new ListItem("- Choose Bill Format -", "0"));
        }
    }
    protected void Bind_Currency()
    {
        strsql = " select * from MAS_Currency";
        DataTable dtcur = DU.getdata(strsql);
        if (dtcur.Rows.Count > 0)
        {
            ddlcurrency.DataSource = dtcur;
            ddlcurrency.DataTextField = "currency_name";
            ddlcurrency.DataValueField = "id";
            ddlcurrency.DataBind();
            ddlcurrency.Items.Insert(0, new ListItem("- Select Currency -", "0"));
        }
    }
    protected void Bind_Supplier(string country, int a)
    {
        if (country == "India" && a == 1)
        {
            strsql = "select LM.LID as LID,LM.LNAME as LNAME from ACC_LEDMAST LM inner join ACC_LEDADDRESS LA on LM.LID=LA.LID where LM.PGID='20' and LA.COUNTRY = '" + country + "' Order By LM.LNAME ASC";
        }
        else
        {
            strsql = "select LM.LID as LID,LM.LNAME as LNAME from ACC_LEDMAST LM inner join ACC_LEDADDRESS LA on LM.LID=LA.LID where LM.PGID='20' and LA.COUNTRY <> '" + country + "' Order By LM.LNAME ASC";
        }
        //strsql = "select LID,Lname from ACC_LEDMAST where PGID='20' Order By LNAME ASC";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            ddlSupplier.DataSource = DT;
            ddlSupplier.DataTextField = "Lname";
            ddlSupplier.DataValueField = "LID";
            ddlSupplier.DataBind();
            ddlSupplier.Items.Insert(0, new ListItem("- Select Supplier -", "0"));
        }
    }
    protected void Enable_TextBoxs()
    {
        strsql = "Select * from IVR_TRANFORMAT where TFOID='" + ddlFormat.SelectedValue + "'";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            //if(DT.Rows[0]["PREPAREDBY"].ToString()=="True")
            //{
            //    txtPreparedBy.Enabled=true;
            //    txtPreparedBy.BackColor = Color.White;
            //}
            //else
            //{
            //     txtPreparedBy.Enabled=false;
            //     txtPreparedBy.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            //}
            //if(DT.Rows[0]["CHECKEDBY"].ToString()=="True")
            //{
            //    txtCheckedBy.Enabled=true;
            //    txtCheckedBy.BackColor = Color.White;
            //}
            //else
            //{
            //    txtCheckedBy.Enabled=false;
            //    txtCheckedBy.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            //}
            //if(DT.Rows[0]["AUTHSIGNATORY"].ToString()=="True")
            //{
            //    txtSignatory.Enabled = true;
            //    txtSignatory.BackColor = Color.White;
            //}
            //else 
            //{
            //    txtSignatory.Enabled = false;
            //    txtSignatory.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            //}
            //if(DT.Rows[0]["NARRATION"].ToString()=="True")
            //{
            //    txtNarration.Enabled = true;
            //    txtNarration.BackColor = Color.White;
            //}
            //else
            //{
            //    txtNarration.Enabled = false;
            //    txtNarration.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            //}
            if (DT.Rows[0]["REMARKS"].ToString() == "True")
            {
                txtRemark.Enabled = true;
                txtRemark.BackColor = Color.White;
            }
            else
            {
                txtRemark.Enabled = false;
                txtRemark.BackColor = ColorTranslator.FromHtml("#d4d0c8");
            }
        }
    }
    private void BindLocations()
    {
        DataTable DTLocation = DU.getdata("SELECT WHSID,WHSLOCATION from IVR_WAREHOUSE");
        DdlLocation.DataSource = DTLocation;
        DdlLocation.DataTextField = "WHSLOCATION";
        DdlLocation.DataValueField = "WHSID";
        DdlLocation.DataBind();
        DdlLocation.Items.Insert(0, new ListItem("- Select Delivery Location -", "0"));
    }
    protected void Bind_CompanyAddress()
    {
        txtBillAddress.Text = "";
        strsql = "Select * from ACC_COMPANY";
        DataTable DTAdd = DU.getdata(strsql);
        if (DTAdd.Rows.Count > 0)
        {
            string state = "";
            string country = "";
            strsql = "select STATENAME from MAS_State Where StateId='" + DTAdd.Rows[0]["StateId"].ToString() + "'";
            DataTable DTState = DU.getdata(strsql);
            if (DTState.Rows.Count > 0)
            {
                state = DTState.Rows[0]["STATENAME"].ToString();
            }
            strsql = "select COUNTRYNAME from MAS_Country Where CountryId='" + DTAdd.Rows[0]["Country"].ToString() + "'";
            DataTable DTCountry = DU.getdata(strsql);
            if (DTCountry.Rows.Count > 0)
            {
                country = DTCountry.Rows[0]["COUNTRYNAME"].ToString();
            }
            StringBuilder sbAddress = new StringBuilder();
            sbAddress.Append(DTAdd.Rows[0]["CompName"].ToString());
            sbAddress.Append("\r" + DTAdd.Rows[0]["ADD1"].ToString());
            if (!DTAdd.Rows[0]["ADD2"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("\r" + DTAdd.Rows[0]["ADD2"].ToString());
            }
            if (!DTAdd.Rows[0]["ADD3"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("\r" + DTAdd.Rows[0]["ADD3"].ToString());
            }
            if (!DTAdd.Rows[0]["ADD4"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("\r" + DTAdd.Rows[0]["ADD4"].ToString());
            }
            if (!DTAdd.Rows[0]["PLACE"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("\r" + DTAdd.Rows[0]["PLACE"].ToString());
            }
            sbAddress.Append("," + state.ToString());
            if (!DTAdd.Rows[0]["PINCODE"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("-" + DTAdd.Rows[0]["PINCODE"].ToString());
            }
            sbAddress.Append("," + country.ToString());
            if (!DTAdd.Rows[0]["Phone"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("\r" + "Phone");
                sbAddress.Append("- " + DTAdd.Rows[0]["Phone"].ToString());
            }
            if (!DTAdd.Rows[0]["Email"].ToString().Equals(string.Empty))
            {
                sbAddress.Append("\r" + "Email");
                sbAddress.Append("- " + DTAdd.Rows[0]["Email"].ToString());
            }
            txtBillAddress.Text = sbAddress.ToString();
        }
    }
    protected void Bind_SupplierOtherDetails()
    {
        strsql = "Select * from ACC_LEDOTHERDETAILS where LID='" + ddlSupplier.SelectedValue + "'";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            if (Convert.ToDouble(DT.Rows[0]["CREDITPERIOD"].ToString()) > 0)
            {
                txtCreditDay.Text = DT.Rows[0]["CREDITPERIOD"].ToString();
                radioCredit.Checked = true;
                radioCash.Checked = false;
            }
            else
            {
                txtCreditDay.Text = "";
                radioCredit.Checked = false;
                radioCash.Checked = true;
            }
            lblVendorCreditLimit.Text = DT.Rows[0]["CREDITLIMIT"].ToString();
        }
        else
        {
            txtCreditDay.Text = "";
            radioCredit.Checked = false;
            radioCash.Checked = true;
        }
    }
    protected void Bind_SupplierBalance()
    {
        strsql = "Select ACTOPENING,ACTOPENING from ACC_LEDMAST where LID='" + ddlSupplier.SelectedValue + "'";
        DataTable DT = DU.getdata(strsql);
        if (DT.Rows.Count > 0)
        {
            lblVenderOB.Text = DT.Rows[0]["ACTOPENING"].ToString();
            if (Convert.ToDouble(DT.Rows[0]["ACTOPENING"].ToString()) > 0)
            {
                lblVenderDrCr.Text = "Cr";
            }
            else
            {
                lblVenderDrCr.Text = "Dr";
            }
        }
    }
    protected bool ValidateVoucherNo()
    {
        //strsql = "select PoVoucherNo from acc_pomain where BillFormatId='" + ddlFormat.SelectedValue + "'and PoVoucherNo='" + txtVoucher.Text.Trim() + "'";
        //DataTable DT = DU.getdata(strsql);
        //if (DT.Rows.Count > 0)
        //{
        //    lblMsg.Text = "";
        //    ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Duplicate P.O. Number');", true);
        //    txtVoucher.Focus();
        //    return false;
        //}
        //else
        //{
        return true;
        //}
    }
    protected void BindCustomData()
    {
        DTMain.Columns.Add("POID");
        DTMain.Columns.Add("PoVoucherNo");
        DTMain.Columns.Add("PoDate", typeof(DateTime));
        DTMain.Columns.Add("Lname");
        DTMain.Columns.Add("DeliveryDate");
        DTMain.Columns.Add("Priority");
        DTMain.Columns.Add("Quantity");
        DTMain.Columns.Add("GrandTotal");
        DTMain.Columns.Add("Status");
        strsql = "Select * from ACC_POMAIN where BILLFORMATID=5 order by POVOUCHERNO asc";
        DTBindPO = DU.getdata(strsql);
        if (DTBindPO.Rows.Count > 0)
        {
            for (int i = 0; i < DTBindPO.Rows.Count; i++)
            {
                string PoVoucherNo = "";
                string Prefix = "";
                string PoNumber = "";
                string Suffix = "";
                DataRow DRMain = DTMain.NewRow();
                DRMain["POID"] = DTBindPO.Rows[i]["POID"].ToString();

                if (DTBindPO.Rows[i]["PoPrefix"].ToString() != string.Empty)
                {
                    Prefix = DTBindPO.Rows[i]["PoPrefix"].ToString() + "/";
                }
                if (DTBindPO.Rows[i]["PoVoucherNo"].ToString() != string.Empty)
                {
                    PoNumber = DTBindPO.Rows[i]["PoVoucherNo"].ToString();
                }
                if (DTBindPO.Rows[i]["PoSuffix"].ToString() != string.Empty)
                {
                    Suffix = "/" + DTBindPO.Rows[i]["PoSuffix"].ToString();
                }
                PoVoucherNo = Prefix + PoNumber + Suffix;
                DRMain["PoVoucherNo"] = PoVoucherNo;
                strsql = "Select LNAME from ACC_LEDMAST where LID='" + DTBindPO.Rows[i]["LID"].ToString() + "'";
                DataTable DTLed = DU.getdata(strsql);
                if (DTLed.Rows.Count > 0)
                {
                    DRMain["Lname"] = DTLed.Rows[0]["LNAME"].ToString();
                }
                if (DTBindPO.Rows[i]["DeliveryDate"].ToString() == "")
                {
                    DRMain["DeliveryDate"] = "--";
                }
                else
                {
                    DRMain["DeliveryDate"] = Convert.ToDateTime(DTBindPO.Rows[i]["DeliveryDate"].ToString()).ToString("dd-MMM-yyyy");
                }
                DRMain["Priority"] = DTBindPO.Rows[i]["Priority"].ToString();
                DRMain["Quantity"] = Convert.ToDouble(DTBindPO.Rows[i]["TotalQty"].ToString()).ToString("N0");
                if (DTBindPO.Rows[i]["GrandTotal"].ToString() != string.Empty)
                {
                    DRMain["GrandTotal"] = Convert.ToDouble(DTBindPO.Rows[i]["GrandTotal"].ToString()).ToString("N2");
                }
                else
                {
                    DRMain["GrandTotal"] = "0.00";
                }
                DRMain["Status"] = DTBindPO.Rows[i]["Status"].ToString();

                DTMain.Rows.Add(DRMain);
            }
        }
        //DTMain.DefaultView.Sort = "povoucherno asc";
        grdDisplay.DataSource = DTMain;
        grdDisplay.DataBind();
    }
    protected void BindInternationalPO()
    {
        DTInternational.Reset();
        DTInternational.Columns.Add("POID");
        DTInternational.Columns.Add("PoVoucherNo");
        DTInternational.Columns.Add("PoDate", typeof(DateTime));
        DTInternational.Columns.Add("Lname");
        DTInternational.Columns.Add("DeliveryDate");
        DTInternational.Columns.Add("Priority");
        DTInternational.Columns.Add("Quantity");
        DTInternational.Columns.Add("GrandTotal");
        DTInternational.Columns.Add("Status");
        strsql = "Select * from ACC_POMAIN where BILLFORMATID=4 order by POVOUCHERNO asc";
        DTBindInterPO = DU.getdata(strsql);
        if (DTBindInterPO.Rows.Count > 0)
        {
            for (int i = 0; i < DTBindInterPO.Rows.Count; i++)
            {
                string PoVoucherNo = "";
                string Prefix = "";
                string PoNumber = "";
                string Suffix = "";
                DataRow DRIMain = DTInternational.NewRow();
                DRIMain["POID"] = DTBindInterPO.Rows[i]["POID"].ToString();

                if (DTBindInterPO.Rows[i]["PoPrefix"].ToString() != string.Empty)
                {
                    Prefix = DTBindInterPO.Rows[i]["PoPrefix"].ToString() + "/";
                }
                if (DTBindInterPO.Rows[i]["PoVoucherNo"].ToString() != string.Empty)
                {
                    PoNumber = DTBindInterPO.Rows[i]["PoVoucherNo"].ToString();
                }
                if (DTBindInterPO.Rows[i]["PoSuffix"].ToString() != string.Empty)
                {
                    Suffix = "/" + DTBindInterPO.Rows[i]["PoSuffix"].ToString();
                }
                PoVoucherNo = Prefix + PoNumber + Suffix;
                DRIMain["PoVoucherNo"] = PoVoucherNo;
                strsql = "Select LNAME from ACC_LEDMAST where LID='" + DTBindInterPO.Rows[i]["LID"].ToString() + "'";
                DataTable DTILed = DU.getdata(strsql);
                if (DTILed.Rows.Count > 0)
                {
                    DRIMain["Lname"] = DTILed.Rows[0]["LNAME"].ToString();
                }
                if (DTBindInterPO.Rows[i]["DeliveryDate"].ToString() == "")
                {
                    DRIMain["DeliveryDate"] = "--";
                }
                else
                {
                    DRIMain["DeliveryDate"] = Convert.ToDateTime(DTBindInterPO.Rows[i]["DeliveryDate"].ToString()).ToString("dd-MMM-yyyy");
                }
                DRIMain["Priority"] = DTBindInterPO.Rows[i]["Priority"].ToString();
                DRIMain["Quantity"] = Convert.ToDouble(DTBindInterPO.Rows[i]["TotalQty"].ToString()).ToString("N0");
                if (DTBindInterPO.Rows[i]["GrandTotal"].ToString() != string.Empty)
                {
                    DRIMain["GrandTotal"] = Convert.ToDouble(DTBindInterPO.Rows[i]["GrandTotal"].ToString()).ToString("N2");
                }
                else
                {
                    DRIMain["GrandTotal"] = "0.00";
                }
                DRIMain["Status"] = DTBindInterPO.Rows[i]["Status"].ToString();
                DTInternational.Rows.Add(DRIMain);
            }
        }
        grdInternational.DataSource = DTInternational;
        grdInternational.DataBind();
    }
    #endregion
    //Dropdown list selected index Event of the Page
    #region
    protected void ddlFormat_SelectedIndexChanged(object sender, EventArgs e)
    {
        //*****************************//
        // 4 For International (Online)//
        // 37 for International (Local)//
        //*****************************//
        ddlcurrency.Items.Clear();
        if (ddlFormat.SelectedValue == "4")//International
        {
            ddlcurrency.Enabled = true;
            string sql = "select * from MAS_Currency where id not in(1)";
            DataTable dtcur = DU.getdata(sql);
            if (dtcur.Rows.Count > 0)
            {
                ddlcurrency.DataSource = dtcur;
                ddlcurrency.DataTextField = "currency_name";
                ddlcurrency.DataValueField = "id";
                ddlcurrency.DataBind();
                ddlcurrency.Items.Insert(0, new ListItem("- Select Currency -", "0"));
            }
            int count = Convert.ToInt32(hidControl.Value);
            for (int i = 1; i <= count; i++)
            {
                TextBox txtRateExcltax = (TextBox)tblItem.Rows[i].FindControl("txtRateExcTax" + i.ToString());
                txtRateExcltax.Text = "";
            }
            Bind_Supplier("India", 2);
            ddlDeliveryTerms.Enabled = true;
        }
        else //Domestic;
        {
            string sql = "select * from MAS_Currency where id = 1";
            DataTable dtcur = DU.getdata(sql);
            if (dtcur.Rows.Count > 0)
            {
                ddlcurrency.DataSource = dtcur;
                ddlcurrency.DataTextField = "currency_name";
                ddlcurrency.DataValueField = "id";
                ddlcurrency.DataBind();
                ddlcurrency.Items.Insert(0, new ListItem("- Select Currency -", "0"));
            }
            ddlcurrency.Items.FindByValue("1").Selected = true;
            ddlcurrency.Enabled = false;
            int count = Convert.ToInt32(hidControl.Value);
            for (int i = 1; i <= count; i++)
            {
                TextBox txtRateExcltax = (TextBox)tblItem.Rows[i].FindControl("txtRateExcTax" + i.ToString());
                txtRateExcltax.Text = "";
            }
            Bind_Supplier("India", 1);
            ddlDeliveryTerms.Enabled = false;
        }
    }
    protected void ddlSupplier_SelectedIndexChanged(object sender, EventArgs e)
    {
        Bind_SupplierOtherDetails();
        Bind_SupplierBalance();
    }
    protected void DdlLocation_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (DdlLocation.SelectedValue == "3")
        {
            string StrQuery = "select compName+', '+Add1+''+Add2+''+Add3+''+Add4+','+place+', PinCode-'+CONVERT(varchar,Pincode)+', Phone No-'+CONVERT(varchar,Phone)+', Fax No-'+Fax+', Email ID-vishnuchit.vats@ctdi.in, Website-'+WebSite as DeliveryAddess from ACC_Company";
            DataTable DTDelivery = DU.getdata(StrQuery);
            if (DTDelivery.Rows.Count > 0)
            {
                txtDeliveryAdd.Text = DTDelivery.Rows[0]["DeliveryAddess"].ToString();
            }
        }
        else
        {
            txtDeliveryAdd.Text = "";
        }
    }
    protected void ddlleased_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    #endregion
    //Send mail After the creation of the Purchase order
    #region
    protected void SendEMail()
    {
        try
        {
            string Payment = "";
            DataTable DtMail = DU.getdata("Select * from Acc_EmailSetting");
            if (DtMail.Rows.Count > 0)
            {
                if (radioCash.Checked == true)
                {
                    Payment = "Advance";
                }
                else if (radioCOD.Checked == true)
                {
                    Payment = "Cash On Delivery";
                }
                else if (radioCredit.Checked == true)
                {
                    Payment = txtCreditDay.Text + "Credit days";
                }
                else if (radioFOC.Checked == true)
                {
                    Payment = "Free Of Cost";
                }
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.To.Add("vishnuchit.vats@ctdi.in,dshukla@ctdi.com");
                mail.Bcc.Add("harish@digitalsolutions.co.in");
                mail.From = new System.Net.Mail.MailAddress(hidemailId.Value, DtMail.Rows[1]["MailDisplayName"].ToString().Trim());
                mail.Subject = "Dis-Account";
                mail.IsBodyHtml = true;
                mail.Body = "<table width='90%' cellpadding='0' cellspacing='0' style='font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal'><tr><td>Dear Sir/Madam</td></tr><tr><td>&nbsp;Following purchase order is waiting for your approval:-</td></tr><tr> <td align='center'><table style='border: 1px solid #818181; width: 80%; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;' cellpadding='0' cellspacing='0'><tr style='background-color: #4D8732;'><td colspan='4' style='color: white; border: 1px solid #818181;' align='left'><b>Purchase Order Detail</b></td></tr><tr><td><b>Bill Format</b></td><td>" + ddlFormat.SelectedItem.ToString() + "</td><td><b>Supplier</b></td><td>" + ddlSupplier.SelectedItem.ToString() + "</td></tr><tr><td><b>Leased Type</b></td><td>" + ddlleased.SelectedItem.ToString() + "</td><td><b>Delivery Location</b></td><td>" + DdlLocation.SelectedItem.ToString() + "</td></tr><tr><td><b>Currency</b></td><td>" + ddlcurrency.SelectedItem.ToString() + "</td><td><b>Priority</b></td><td>" + DdlPriority.SelectedItem.ToString() + "</td></tr><tr><td><b>Payment Term</b></td><td>" + Payment + "</td><td></td></tr></table></td></tr><tr><td><table style='border: 1px solid #818181; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;' cellpadding='0' cellspacing='0'><tr style='background-color: #4D8732;'><td colspan='5' style='color: white; border: 1px solid #818181;'><b>Item Detail</b></td></tr><tr><td style='border: 1px solid #818181; width: 40%;'><b>Item Name / Item Code</b></td><td style='border: 1px solid #818181; width: 10%;'><b>UOM</b></td><td style='border: 1px solid #818181; width: 10%;'><b>Qty</b></td><td style='border: 1px solid #818181; width: 10%;'><b>Rate</b></td><td style='border: 1px solid #818181; width: 15%;'><b>Amount Payable</b></td></tr>" + Body + "</table></td></tr><tr><td><table  cellpadding='0' cellspacing='0'><tr><td style='border: 1px solid #818181; width: 40%;'></td><td style='border: 1px solid #818181; width: 10%;'><b>Item Total</b></td><td style='border: 1px solid #818181; width: 10%;' align='right'>" + Convert.ToDecimal(txtTotalItem.Text).ToString("N0") + "</td><td style='border: 1px solid #818181; width: 10%;'><b>Taxable Amount</b></td><td align='right' style='border: 1px solid #818181; width: 15%;'>" + Convert.ToDecimal(txtTaxableAmt.Text).ToString("N2") + "</td></tr></table></td></tr><tr><td><b>Thanks & Regards</b></td></tr><tr><td><a href='http://103.13.97.96/demo/main/inventory/viewPurchaseOrder.aspx?redirect=PM' target='_blank'>Click here for login</a></td></tr></table>";
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Host = DtMail.Rows[1]["MailHost"].ToString().Trim();
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential(DtMail.Rows[1]["MailUserID"].ToString().Trim(), DtMail.Rows[1]["MailPassword"].ToString().Trim());
                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void SendEMailForRevision()
    {
        try
        {
            DataTable DtMail = DU.getdata("Select * from Acc_EmailSetting");
            if (DtMail.Rows.Count > 0)
            {
                System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
                mail.To.Add("sanjay.samal@ctdi.in");
                mail.Bcc.Add("harish@digitalsolutions.co.in");
                mail.From = new System.Net.Mail.MailAddress(hidemailId.Value, DtMail.Rows[1]["MailDisplayName"].ToString().Trim());
                mail.Subject = "Testing-Purpose";
                mail.IsBodyHtml = true;
                mail.Body = "<table width='80%' cellpadding='0' cellspacing='0' style='font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal'><tr><td>Dear Sir/Madam</td></tr><tr><td>&nbsp;Following purchase order is waiting for your approval:-</td></tr><tr><td align='center'><table style='border: 1px solid #818181; width: 80%; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;' cellpadding='0' cellspacing='0'><tr style='background-color: #4D8732;'><td colspan='4' style='color: white; border: 1px solid #818181;' align='left'><b>Purchase Order Detail</b></td></tr><tr><td><b>Bill Format</b></td><td>" + ddlFormat.SelectedItem.ToString() + "</td><td><b>Supplier</b></td><td>" + ddlSupplier.SelectedItem.ToString() + "</td></tr><tr><td><b>Leased Type</b></td><td>" + ddlleased.SelectedItem.ToString() + "</td><td><b>Delivery Location</b></td><td>" + DdlLocation.SelectedItem.ToString() + "</td></tr><tr><td><b>Currency</b></td><td>" + ddlcurrency.SelectedItem.ToString() + "</td><td></td></tr></table></td></tr><tr><td><table style='border: 1px solid #818181; width: 100%; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;' cellpadding='0' cellspacing='0'><tr style='background-color: #4D8732;'><td colspan='5' style='color: white; border: 1px solid #818181;'><b>Item Detail</b></td></tr><tr><td style='border: 1px solid #818181; width: 40%;'><b>Item Name / Item Code</b></td><td style='border: 1px solid #818181; width: 10%;'><b>UOM</b></td><td style='border: 1px solid #818181; width: 10%;'><b>Qty</b></td><td style='border: 1px solid #818181; width: 10%;'><b>Rate</b></td><td style='border: 1px solid #818181; width: 15%;'><b>Amount Payable</b></td></tr>" + Body + "</table></td></tr><tr><td align='right'><table style='border: 1px solid #818181; width: 40%; font-family: Arial, Helvetica, sans-serif; font-size: small; font-weight: normal;' cellpadding='0' cellspacing='0'><tr><td style='border: 1px solid #818181; width: 16%;'><b>Item Total</b></td><td style='border: 1px solid #818181; text-align: right; width: 14%;'>" + Convert.ToDecimal(txtTotalItem.Text) + "</td></tr><tr><td style='border: 1px solid #818181;'><b>Taxable Amount</b></td><td style='border: 1px solid #818181; text-align: right;'>" + Convert.ToDecimal(txtTaxableAmt.Text) + "</td></tr></table></td></tr><tr><td><b>Thanks & Regards</b></td></tr><tr><td><a href='http:\\103.13.97.96/demo/index.aspx' target='_blank'>Click here for login</a></td></tr></table>";
                System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
                smtp.Host = DtMail.Rows[1]["MailHost"].ToString().Trim();
                smtp.Port = 587;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials = new System.Net.NetworkCredential(DtMail.Rows[1]["MailUserID"].ToString().Trim(), DtMail.Rows[1]["MailPassword"].ToString().Trim());
                smtp.EnableSsl = true;
                smtp.Send(mail);
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void MailTextBody(string ItemName, string ItemCode, string UOM, string Qty, string Rate, string Amount)
    {
        Body += "<tr><td style='border:1px solid #818181;'>" + ItemName + "&nbsp;/&nbsp;" + ItemCode + "</td><td style='border:1px solid #818181;'>" + UOM + "</td><td style='border:1px solid #818181; text-align:right;'>" + Qty + "</td><td style='border:1px solid #818181; text-align:right;'>" + Rate + "</td><td style='border:1px solid #818181; text-align:right;'>" + Amount + "</td></tr>";
    }
    #endregion
    //Save or cancel button click or the    
    #region
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            if (ValidateVoucherNo())
            {
                string sql = "select max(podate) as date from acc_pomain";
                DataTable dt = DU.getdata(sql);
                if (dt.Rows.Count > 0 && dt.Rows[0][0].ToString() != string.Empty)
                {
                    //if(Convert.ToDateTime(System.DateTime.Today.ToShortDateString()) >= Convert.ToDateTime(Convert.ToDateTime(dt.Rows[0]["date"].ToString()).ToShortDateString()))
                    //{

                    InsertPurchaseOrderMain();
                    InsertPurchaseOrderDetails();

                    SendEMail();

                    Response.Redirect("PurchaseOrder.aspx?v=u");
                    //}
                    //else
                    //{                        
                    //lblMsg.Attributes.Add("class", "false");
                    //}
                }
                else
                {
                    InsertPurchaseOrderMain();
                    InsertPurchaseOrderDetails();
                    SendEMail();
                    Response.Redirect("PurchaseOrder.aspx?v=u");
                }
            }
            else
            {
                return;
            }
        }
        catch (Exception Ex)
        {
            lblMsg.Text = Ex.Message;
        }
    }
    //***************Documentation for Purchase Order*************
    // Status Column in Acc_POMAIN table

    //  1 for Purchase Order Enter into DataBase.

    //  2 for Purchase Order Edit Into DataBase.

    //  3 for Purchase Order Approved By the Manager.
    //  4 for Purchase Order Sent for Revision By Manager.

    //  5 For Purchase Order Approved By Finance.
    //  6 For Purchase Order Sent For Revision By Finance.
    //  7 For Purchase Order Reject By Finance.

    //  8 For Purchase Order Approved By Admin.
    //  9 For Purchase Order Sent For Revision BY Admin.
    //  10 For Purchase Order Reject By Admin

    //*************************************************************
    protected void InsertPurchaseOrderMain()
    {
        string Podate = "";
        string DeliveryDate = "";
        string ModeOfDispatch = "";
        string AcceptanceCriteria = "";
        string Validityofpo = "";
        string Insurance = "";
        string Warranty = "";
        string Freight = "";
        string termofdelivery = "";
        int cash_credit = 0;
        if (radioCash.Checked == true)//Advance
        {
            cash_credit = 0;//for advance
        }
        else if (radioCOD.Checked == true)//Cash on delivery
        {
            cash_credit = 2;//for COD
        }
        else if (radioCredit.Checked == true)//credit on days
        {
            cash_credit = 1;//for Credit on days
        }
        else if (radioFOC.Checked == true)
        {
            cash_credit = 3;//for Free of Cost.
        }
        string[] str1 = System.DateTime.Today.ToShortDateString().Split('/');
        Podate = str1[1].ToString() + "/" + str1[0].ToString() + "/" + str1[2].ToString();
        if (txtDeliveryDate.Text != "")
        {
            string[] str = txtDeliveryDate.Text.ToString().Split('/');
            DeliveryDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
        }
        else
        {
            DeliveryDate = null;
        }
        if (RblModeDispatch.SelectedValue == "0")
        {
            ModeOfDispatch = txtModeDispatch.Text;
        }
        else
        {
            ModeOfDispatch = RblModeDispatch.SelectedItem.Text;
        }
        if (RblAcceptanceCriteria.SelectedValue == "0")
        {
            AcceptanceCriteria = txtAcceptanceCriteria.Text;
        }
        else
        {
            AcceptanceCriteria = RblAcceptanceCriteria.SelectedItem.Text;
        }
        if (RblvalidityofPO.SelectedValue == "0")
        {
            Validityofpo = txtvalidityofPO.Text;
        }
        else
        {
            Validityofpo = RblvalidityofPO.SelectedItem.Text;
        }
        if (RblInsurance.SelectedValue == "0")
        {
            Insurance = txtInsurance.Text;
        }
        else
        {
            Insurance = RblInsurance.SelectedItem.Text;
        }
        if (RBLFreight.SelectedValue == "0")
        {
            Freight = txtfreight.Text;
        }
        else
        {
            Freight = RBLFreight.SelectedItem.Text;
        }
        if (RblWarranty.SelectedValue == "0")
        {
            Warranty = txtWarranty.Text;
        }
        else
        {
            Warranty = RblWarranty.SelectedItem.Text;
        }
        if (ddlFormat.SelectedValue == "4")
        {
            termofdelivery = ddlDeliveryTerms.SelectedItem.Text + "(" + txtDeliveryTerms.Text;
        }
        else
        {
            termofdelivery = txtDeliveryTerms.Text;
        }
        try
        {
            SqlParameter[] sparam ={
                                        new SqlParameter ("@BillFormatId",ddlFormat.SelectedValue),
                                        new SqlParameter ("@LID",ddlSupplier.SelectedValue),                                       
                                        new SqlParameter ("@PODate",Podate),
                                        new SqlParameter ("@PoPrefix",""),
                                        new SqlParameter ("@PoVoucherNo",""),
                                        new SqlParameter ("@PoSuffix",""),
                                        new SqlParameter ("@TaxGroupId","0"),
                                        new SqlParameter ("@DeliveryLocation",DdlLocation.SelectedValue),
                                        new SqlParameter ("@Cash_Credit",cash_credit.ToString()),
                                        new SqlParameter ("@CreditDay",txtCreditDay.Text.Trim()), 
                                        new SqlParameter ("@Priority",DdlPriority.SelectedItem.Text),
                                        new SqlParameter ("@TotalQty",Convert.ToDecimal(txtTotalItem.Text.Trim())),
                                        new SqlParameter ("@LeasedType",ddlleased.SelectedValue),
                                        //new SqlParameter ("@PreTaxTotal",Convert.ToDecimal(txtPreTotalTax.Text.Trim())),
                                        new SqlParameter ("@PreTaxTotal",Convert.ToDecimal("0.0")),
                                        new SqlParameter ("@TaxableAmt",Convert.ToDecimal(txtTaxableAmt.Text.Trim())),
                                        new SqlParameter ("@TaxAmt",Convert.ToDecimal("0.0")),
                                        new SqlParameter ("@PostTaxTotal",Convert.ToDecimal(txtPostTaxTotal.Text.Trim())),
                                        new SqlParameter ("@RoundOff",Convert.ToDecimal(txtRoundoff.Text.Trim())),
                                        new SqlParameter ("@GrandTotal",Convert.ToDecimal(txtGrandTotal.Text.Trim())),
                                        new SqlParameter ("@BillingAddress",txtBillAddress.Text.Trim().Replace("\r","<br/>")),
                                        new SqlParameter ("@DeliveryAddress",txtDeliveryAdd.Text.Trim().Replace("\r","<br/>")),
                                        new SqlParameter ("@DeliveryTerms",termofdelivery),
                                        new SqlParameter ("@DeliveryMode",ModeOfDispatch.Trim()),                                        
                                        new SqlParameter ("@DeliveryDate",DeliveryDate),
                                        new SqlParameter ("@AcceptanceCriteria",AcceptanceCriteria.Trim()),
                                        new SqlParameter ("@ValidityOfPO",Validityofpo.Trim()),
                                        new SqlParameter ("@Insurance",Insurance.Trim()),
                                        new SqlParameter ("@Warranty",Warranty.Trim()),
                                        new SqlParameter ("@AnySpecialCondition",txtanyspecialcondition.Text.Trim()),
                                        new SqlParameter ("@Remarks",txtRemark.Text.Trim()),
                                        new SqlParameter ("@Status","1"),
                                        new SqlParameter ("@Cname",Session["username"].ToString()),
                                        new SqlParameter ("@stages","1"),
                                        new SqlParameter ("@vendorquoteref",txtvendorref.Text),
                                        new SqlParameter ("@currency",ddlcurrency.SelectedValue),
                                        new SqlParameter ("@exchangerate","1"),
                                        new SqlParameter ("@Handling_Packing",ddlhandling.SelectedItem.ToString()),
                                        new SqlParameter ("@FreightFWD",txtfreightfwd.Text),
                                        new SqlParameter ("@ImportAC_No",txtimpacno.Text),
                                        new SqlParameter ("@Revision_No","0"),
                                        new SqlParameter ("@TaxDuties",txttaxDuties.Text),
                                        new SqlParameter ("@ShortClose",false),
                                        new SqlParameter ("@Freight",Freight)
                           };
            int reuslt = DU.executeprocedure("USP_ACC_SavePurOrder_Main", sparam);
            if (reuslt > 0)
            {
                strsql = "Select Ident_Current('ACC_POMAIN')as POID";
                DataTable DT = DU.getdata(strsql);
                if (DT.Rows.Count > 0)
                {
                    POID = DT.Rows[0]["POID"].ToString();
                }
                lblMsg.Text = "Purchase Order Created Successfully";
            }
        }
        catch (Exception Ex)
        {
            lblMsg.Text = Ex.Message;
        }
    }
    protected void InsertPurchaseOrderDetails()
    {
        string TempTaxType = ""; string TempTaxtypeId = "";
        try
        {
            int result = 0; string ddlmpnNo = "";
            int count = Convert.ToInt32(hidControl.Value.ToString());
            for (int i = 1; i <= count; i++)
            {
                TextBox txtItem = (TextBox)tblItem.Rows[i].FindControl("txtItem" + i.ToString());
                TextBox txtQty = (TextBox)tblItem.Rows[i].FindControl("txtQty" + i.ToString());
                TextBox txtRateExcTax = (TextBox)tblItem.Rows[i].FindControl("txtRateExcTax" + i.ToString());
                TextBox txtAmountPayable = (TextBox)tblItem.Rows[i].FindControl("txtAmountPayable" + i.ToString());
                TextBox txtUnit = (TextBox)tblItem.Rows[i].FindControl("txtUnit" + i.ToString());
                DropDownList ddlMpn = (DropDownList)tblItem.Rows[i].FindControl("ddlmpn" + i.ToString());
                if (ddlFormat.SelectedValue == "4")//international
                {
                    TempTaxType = "Imported";
                    TempTaxtypeId = "22";
                }
                else
                {
                    TempTaxType = "Domestic";
                    TempTaxtypeId = "0";
                }
                if (ddlMpn.SelectedItem.ToString() == "")
                {
                    ddlmpnNo = "0";
                }
                else
                {
                    ddlmpnNo = ddlMpn.SelectedItem.ToString();
                }
                if (txtItem.Text != "")
                {
                    string[] itemname = txtItem.Text.Split('\\');
                    decimal taxAmt = 0;
                    decimal taxableAmt = 0;
                    string ItemId = "";
                    string UOMID = "";
                    //strsql = "Select ITMID, PRIMARY_UOMID from IVR_ITEM where ITMID='" + ddlItem.SelectedValue + "'";
                    strsql = "Select ITMID, PRIMARY_UOMID from IVR_ITEM where ITMCODE='" + itemname[1] + "'";
                    DataTable DT = DU.getdata(strsql);
                    {
                        if (DT.Rows.Count > 0)
                        {
                            UOMID = DT.Rows[0]["PRIMARY_UOMID"].ToString();
                            ItemId = DT.Rows[0]["ITMID"].ToString();
                        }
                    }
                    taxableAmt = Convert.ToDecimal(txtQty.Text.Trim()) * Convert.ToDecimal(txtRateExcTax.Text.Trim());
                    SqlParameter[] sparam =
                                    {
                                        new SqlParameter ("@PoId",POID.ToString()),
                                        //new SqlParameter ("@ItemId",ddlItem.SelectedValue),
                                        new SqlParameter ("@MPNNO",ddlmpnNo),
                                        new SqlParameter ("@ItemId",ItemId.ToString()),
                                        new SqlParameter ("@UomId",UOMID.ToString()),
                                        new SqlParameter ("@ItemQty",Convert.ToDecimal(txtQty.Text)),
                                        new SqlParameter ("@RateInclTax",Convert.ToDecimal("0")),
                                        new SqlParameter ("@RateExclTax",Convert.ToDecimal(txtRateExcTax.Text)),
                                        new SqlParameter ("@TaxableAmt",taxableAmt),
                                        new SqlParameter ("@TaxType",TempTaxType.ToString()),
                                        new SqlParameter ("@TaxTypeId",TempTaxtypeId.ToString()),
                                        new SqlParameter ("@TaxGroupId","0"),            
                                        new SqlParameter ("@TaxRate",Convert.ToDecimal("0")),
                                        new SqlParameter ("@TaxAmt",taxAmt),
                                        new SqlParameter ("@TotalAmount",Convert.ToDecimal(txtAmountPayable.Text.Trim())),
                                        new SqlParameter ("@PurReceiveQty","0")
                                    };
                    result += DU.executeprocedure("USP_ACC_SavePurOrder_Details", sparam);
                    MailTextBody(itemname[0], itemname[1], txtUnit.Text, Convert.ToDecimal(txtQty.Text).ToString(), Convert.ToDecimal(txtRateExcTax.Text).ToString(), Convert.ToDecimal(taxableAmt).ToString("N2"));
                }
            }
            if (result > 0)
            {
                lblMsg.Text = "Purchase Order Created Successfully";
            }
        }
        catch (Exception Ex)
        {
            lblMsg.Text = Ex.Message;
            return;
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("../../Welcome.aspx");
    }
    #endregion
    //Gridview Event of the Purchase order
    #region
    //for InterNational PO
    protected void grdInternational_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grdInternational.PageIndex = e.NewPageIndex;
        BindInternationalPO();
    }
    protected void grdInternational_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "editpo")
        {
            string key = e.CommandArgument.ToString();
            Response.Redirect("EditPurchaseOrder.aspx?Poid=" + key.ToString());
        }
    }
    protected void grdInternational_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Pager)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridview_alternate'");
            }
            else if (e.Row.RowState == DataControlRowState.Normal)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridviewitem'");
            }
        }
    }
    protected void grdInternational_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string PoId = grdInternational.DataKeys[e.Row.RowIndex].Value.ToString();
            strsql = " Select Status,stages from ACC_POMAIN where POID='" + PoId + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                Label lblStatusOfPO = (Label)e.Row.Cells[4].FindControl("lblStatusOfPO");
                if (DT.Rows[0]["Status"].ToString() == "1")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = true;
                    e.Row.Cells[5].FindControl("imgLock").Visible = false;
                    lblStatusOfPO.Text = "Sent To Manager";
                }
                if (DT.Rows[0]["Status"].ToString() == "2")
                {
                    lblStatusOfPO.Text = "Sent To Manager";
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = true;
                    e.Row.Cells[5].FindControl("imgLock").Visible = false;
                }
                if (DT.Rows[0]["Status"].ToString() == "3")
                {
                    lblStatusOfPO.Text = "Sent To Finance";
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                }
                if (DT.Rows[0]["Status"].ToString() == "4")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = true;
                    e.Row.Cells[5].FindControl("imgLock").Visible = false;
                    lblStatusOfPO.Text = "Sent For Revision By Manager";
                }
                if (DT.Rows[0]["Status"].ToString() == "5")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Sent To Admin";
                }
                if (DT.Rows[0]["Status"].ToString() == "6")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Sent To Revision By Finance";
                }
                if (DT.Rows[0]["Status"].ToString() == "7")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Reject By Finance.";
                }
                if (DT.Rows[0]["Status"].ToString() == "8")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Approved By Admin";
                }
                if (DT.Rows[0]["Status"].ToString() == "9")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Sent For Revision By Admin.";
                }
                if (DT.Rows[0]["Status"].ToString() == "10")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Reject By Admin.";
                }
            }
            e.Row.Cells[4].FindControl("lbtnview").Visible = true;
            GridView GrdPOChild = (GridView)e.Row.FindControl("gvPOIRemarksChild");
            string SqlChildRemarks = "select ACC_POREMARKS.POSTAGE,ACC_POREMARKS.REMARKS,ACC_POREMARKS.REVISIONREMARK,ACC_POREMARKS.REVISIONORDER,ACC_POREMARKS.REJECTREMARK,ACC_POMAIN.PODATE from ACC_POREMARKS inner join ACC_POMAIN on ACC_POMAIN.POID=ACC_POREMARKS.POID where ACC_POMAIN.POID='" + PoId + "'";
            DataTable DTPurchaseRemarks = DU.getdata(SqlChildRemarks);
            DataTable DTChildPO = new DataTable();
            DTChildPO.Columns.Add("POSTAGE", typeof(string));
            DTChildPO.Columns.Add("REMARKS", typeof(string));
            DTChildPO.Columns.Add("REVISIONORDER", typeof(string));
            DTChildPO.Columns.Add("CDATE", typeof(string));
            DTChildPO.Columns.Add("CTIME", typeof(string));
            if (DTPurchaseRemarks.Rows.Count > 0)
            {
                for (int i = 0; i < DTPurchaseRemarks.Rows.Count; i++)
                {
                    DataRow DR = DTChildPO.NewRow();
                    if (DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString() == "2")
                    {
                        DR["POSTAGE"] = "Manager";
                    }
                    if (DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString() == "3")
                    {
                        DR["POSTAGE"] = "Finance";
                    }
                    if (DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString() == "4")
                    {
                        DR["POSTAGE"] = "Admin";
                    }
                    //DR["POSTAGE"] = DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString();
                    DR["REMARKS"] = DTPurchaseRemarks.Rows[i]["REMARKS"].ToString();
                    DR["REVISIONORDER"] = DTPurchaseRemarks.Rows[i]["REVISIONORDER"].ToString();
                    DR["CDATE"] = Convert.ToDateTime(DTPurchaseRemarks.Rows[i]["PODATE"].ToString()).ToString("dd-MMM-yyyy");
                    //DR["CTIME"] = Convert.ToDateTime(DTPurchaseRemarks.Rows[i]["PODATE"].ToString()).ToString("hh:mm:ss tt");
                    DTChildPO.Rows.Add(DR);
                }
            }
            GrdPOChild.DataSource = DTChildPO;
            GrdPOChild.DataBind();
        }
    }
    //For Domestic PO

    //protected void grdDisplay_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
    //{
    //    grdDisplay.PageIndex = e.NewPageIndex;
    //    BindCustomData();
    //}
    protected void grdDisplay_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "editpo")
        {
            string key = e.CommandArgument.ToString();
            Response.Redirect("EditPurchaseOrder.aspx?Poid=" + key.ToString());
        }
    }
    protected void grdDisplay_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string PoId = grdDisplay.DataKeys[e.Row.RowIndex].Value.ToString();
            strsql = " Select Status,stages from ACC_POMAIN where POID='" + PoId + "'";
            DataTable DT = DU.getdata(strsql);
            if (DT.Rows.Count > 0)
            {
                Label lblStatusOfPO = (Label)e.Row.Cells[4].FindControl("lblStatusOfPO");
                if (DT.Rows[0]["Status"].ToString() == "1")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = true;
                    e.Row.Cells[5].FindControl("imgLock").Visible = false;
                    lblStatusOfPO.Text = "Sent To Manager";
                }
                if (DT.Rows[0]["Status"].ToString() == "2")
                {
                    lblStatusOfPO.Text = "Sent To Manager";
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = true;
                    e.Row.Cells[5].FindControl("imgLock").Visible = false;
                }
                if (DT.Rows[0]["Status"].ToString() == "3")
                {
                    lblStatusOfPO.Text = "Sent To Finance";
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                }
                if (DT.Rows[0]["Status"].ToString() == "4")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = true;
                    e.Row.Cells[5].FindControl("imgLock").Visible = false;
                    lblStatusOfPO.Text = "Sent For Revision By Manager";
                }
                if (DT.Rows[0]["Status"].ToString() == "5")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Sent To Admin";
                }
                if (DT.Rows[0]["Status"].ToString() == "6")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Sent To Revision By Finance";
                }
                if (DT.Rows[0]["Status"].ToString() == "7")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Reject By Finance.";
                }
                if (DT.Rows[0]["Status"].ToString() == "8")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Approved By Admin";
                }
                if (DT.Rows[0]["Status"].ToString() == "9")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Sent For Revision By Admin.";
                }
                if (DT.Rows[0]["Status"].ToString() == "10")
                {
                    e.Row.Cells[5].FindControl("lnkEdit").Visible = false;
                    e.Row.Cells[5].FindControl("imgLock").Visible = true;
                    lblStatusOfPO.Text = "Reject By Admin.";
                }
            }
            e.Row.Cells[4].FindControl("lbtnview").Visible = true;
            GridView GrdPOChild = (GridView)e.Row.FindControl("gvPORemarksChild");
            string SqlChildRemarks = "select ACC_POREMARKS.POSTAGE,ACC_POREMARKS.REMARKS,ACC_POREMARKS.REVISIONREMARK,ACC_POREMARKS.REVISIONORDER,ACC_POREMARKS.REJECTREMARK,ACC_POMAIN.PODATE from ACC_POREMARKS inner join ACC_POMAIN on ACC_POMAIN.POID=ACC_POREMARKS.POID where ACC_POMAIN.POID='" + PoId + "'";
            DataTable DTPurchaseRemarks = DU.getdata(SqlChildRemarks);
            DataTable DTChildPO = new DataTable();
            DTChildPO.Columns.Add("POSTAGE", typeof(string));
            DTChildPO.Columns.Add("REMARKS", typeof(string));
            DTChildPO.Columns.Add("REVISIONORDER", typeof(string));
            DTChildPO.Columns.Add("CDATE", typeof(string));
            DTChildPO.Columns.Add("CTIME", typeof(string));
            if (DTPurchaseRemarks.Rows.Count > 0)
            {
                for (int i = 0; i < DTPurchaseRemarks.Rows.Count; i++)
                {
                    DataRow DR = DTChildPO.NewRow();
                    if (DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString() == "2")
                    {
                        DR["POSTAGE"] = "Manager";
                    }
                    if (DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString() == "3")
                    {
                        DR["POSTAGE"] = "Finance";
                    }
                    if (DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString() == "4")
                    {
                        DR["POSTAGE"] = "Admin";
                    }
                    //DR["POSTAGE"] = DTPurchaseRemarks.Rows[i]["POSTAGE"].ToString();
                    DR["REMARKS"] = DTPurchaseRemarks.Rows[i]["REMARKS"].ToString();
                    DR["REVISIONORDER"] = DTPurchaseRemarks.Rows[i]["REVISIONORDER"].ToString();
                    DR["CDATE"] = Convert.ToDateTime(DTPurchaseRemarks.Rows[i]["PODATE"].ToString()).ToString("dd-MMM-yyyy");
                    //DR["CTIME"] = Convert.ToDateTime(DTPurchaseRemarks.Rows[i]["PODATE"].ToString()).ToString("hh:mm:ss tt");
                    DTChildPO.Rows.Add(DR);
                }
            }
            GrdPOChild.DataSource = DTChildPO;
            GrdPOChild.DataBind();
        }
    }
    protected void grdDisplay_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType != DataControlRowType.Pager)
        {
            if (e.Row.RowState == DataControlRowState.Alternate)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridview_alternate'");
            }
            else if (e.Row.RowState == DataControlRowState.Normal)
            {
                e.Row.Attributes.Add("onmouseover", "this.className='rowhover'");
                e.Row.Attributes.Add("onmouseout", "this.className='gridviewitem'");
            }
        }
    }
    #endregion
}